package com.queen.restaurant.service;

import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.queen.restaurant.dao.CommentRestaurantDao;
import com.queen.restaurant.dao.OrderDao;
import com.queen.restaurant.dao.RestaurantDao;
import com.queen.restaurant.domain.CommentRestaurant;
import com.queen.restaurant.domain.Order;
import com.queen.restaurant.domain.Restaurant;

@Service
public class CommentRestaurantService {
	
	@Autowired
	private CommentRestaurantDao commentRestaurantDao;
	@Autowired
	private OrderDao orderDao;
	
	public void insertCommentRestaurant(CommentRestaurant commentRestaurant){
		Order order = commentRestaurant.getOrder();
		order.setCanComment(false);
		orderDao.update(order);
		
		SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式化当前系统日期
		String commentTime = dateFm.format(new java.util.Date());
		commentRestaurant.setCommentTime(commentTime);
		
		commentRestaurantDao.getRestaurantAvgRank(order.getRestaurant().getId());
		commentRestaurantDao.save(commentRestaurant);
	}
}
